﻿<view:BaseView x:Class="ModernUILogViewer.Pages.Home"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:content="clr-namespace:ModernUILogViewer.Content"
             xmlns:view="clr-namespace:ModernUILogViewer.View"
             xmlns:vm="clr-namespace:ModernUILogViewer.ViewModel"
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:pages="clr-namespace:ModernUILogViewer.Pages"
             xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"                
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"  
             xmlns:conv="clr-namespace:ModernUILogViewer.Converters"
             xmlns:helper="clr-namespace:ModernUILogViewer.Elements.Helpers"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             DataContext="{Binding Source={StaticResource mainVM}, Path=HomeVM}"
             AllowDrop="True"
    >

    <helper:DragDropBehaviour.DropCommand>
        <Binding Path="DropCommand" />
    </helper:DragDropBehaviour.DropCommand>


    <UserControl.Resources>
        <conv:NullToBooleanConverter x:Key="nulltobooleanconverter" />
        <conv:FilenameConverter x:Key="fileconverter" />
    </UserControl.Resources>
    
    <!--<Grid>-->
        <DockPanel>
            <Grid DockPanel.Dock="Top">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <StackPanel Orientation="Horizontal">
                    <mui:ModernButton 
                        ToolTip="Open files"
                        Command="{Binding Open}" 
                        EllipseDiameter="24" IconWidth="16" IconHeight="16"                           
                        VerticalAlignment="Top"
                        IconData="F1 M 19,50L 28,34L 63,34L 54,50L 19,50 Z M 19,28.0001L 35,28C 36,25 37.4999,24.0001 37.4999,24.0001L 48.75,24C 49.3023,24 50,24.6977 50,25.25L 50,28L 53.9999,28.0001L 53.9999,32L 27,32L 19,46.4L 19,28.0001 Z"              
                    />
                    <mui:ModernButton 
                        x:Name="reloadButton"
                        ToolTip="Reload files"
                        Command="{Binding ReloadFile}" 
                        Margin="{StaticResource DefaultLeftMargin}"
                        EllipseDiameter="24" IconWidth="16" IconHeight="16"                           
                        VerticalAlignment="Top"
                        IconData="F1 M 38,20.5833C 42.9908,20.5833 47.4912,22.6825 50.6667,26.046L 50.6667,17.4167L 55.4166,22.1667L 55.4167,34.8333L 42.75,34.8333L 38,30.0833L 46.8512,30.0833C 44.6768,27.6539 41.517,26.125 38,26.125C 31.9785,26.125 27.0037,30.6068 26.2296,36.4167L 20.6543,36.4167C 21.4543,27.5397 28.9148,20.5833 38,20.5833 Z M 38,49.875C 44.0215,49.875 48.9963,45.3932 49.7703,39.5833L 55.3457,39.5833C 54.5457,48.4603 47.0852,55.4167 38,55.4167C 33.0092,55.4167 28.5088,53.3175 25.3333,49.954L 25.3333,58.5833L 20.5833,53.8333L 20.5833,41.1667L 33.25,41.1667L 38,45.9167L 29.1487,45.9167C 31.3231,48.3461 34.483,49.875 38,49.875 Z "
                        IsEnabled="{Binding ListFiles, Converter={StaticResource nulltobooleanconverter}, ConverterParameter='false'}"
                    />
                </StackPanel>
                <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
                    <mui:ModernButton 
                        ToolTip="Open with external program"
                        Command="{Binding OpenWithExternalEditor}" CommandParameter="{Binding SelectedLogEntry}" 
                        Margin="{StaticResource DefaultRightMargin}"
                        EllipseDiameter="24" IconWidth="16" IconHeight="16"                           
                        VerticalAlignment="Top"
                        HorizontalAlignment="Right"
                        IconData="{StaticResource openExecutablePathData}"
                        
                    >
                        <mui:ModernButton.Style>
                            <Style TargetType="{x:Type mui:ModernButton}">
                                <Setter Property="IsEnabled" Value="False" />
                                <Style.Triggers>
                                    <MultiDataTrigger>
                                        <MultiDataTrigger.Conditions>
                                            <Condition Binding="{Binding SelectedLogEntry, Converter={StaticResource nulltobooleanconverter}, ConverterParameter='false'}" Value="True" />
                                            <Condition Binding="{Binding Source={StaticResource mainVM}, Path=ExternalEditorVM.ExePath,  Converter={StaticResource nulltobooleanconverter}, ConverterParameter='False'}" Value="True" />
                                        </MultiDataTrigger.Conditions>
                                        <Setter Property="IsEnabled" Value="True" />
                                    </MultiDataTrigger>
                                </Style.Triggers>
                            </Style>
                        </mui:ModernButton.Style>
                    </mui:ModernButton>
                    <mui:ModernButton 
                        x:Name="copyButton"                        
                        ToolTip="Copy log message to clipboard"
                        Command="{x:Static view:ViewCommands.CopyTextToClipboard}" CommandParameter="{Binding SelectedLogEntry.Message}" 
                        Margin="{StaticResource DefaultRightMargin}"
                        EllipseDiameter="24" IconWidth="16" IconHeight="16"                           
                        VerticalAlignment="Top"
                        HorizontalAlignment="Right"
                        IconData="{StaticResource copyPathData}"
                        IsEnabled="{Binding SelectedLogEntry, Converter={StaticResource nulltobooleanconverter}, ConverterParameter='false'}"
                    />                    
                </StackPanel>
            </Grid>            

            <!--<TextBlock HorizontalAlignment="Center" Text="{Binding CurrentFilename, Converter={StaticResource fileconverter}}" DockPanel.Dock="Top" Margin="{StaticResource DefaultMargin}"></TextBlock>-->
            
            <Grid DockPanel.Dock="Bottom" Style="{StaticResource ContentRoot}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="56*" />
                    <RowDefinition Height="6" />
                    <RowDefinition Height="30*" />
                    <RowDefinition Height="8*" />
                </Grid.RowDefinitions>

                <pages:LayoutUpper Margin="{StaticResource DefaultTopMargin}" />

                <GridSplitter Grid.Row="1" />

                <content:ContentLogEntryMessage Grid.Row="2" />

                <!-- optional status -->
                <Grid Margin="{StaticResource StatusMargin}" Grid.Row="3">
                    <Rectangle />
                    <TextBlock Text="{Binding Status}" />
                </Grid>

            </Grid>
            
        </DockPanel>        

    <!--</Grid>-->
    
    
    <i:Interaction.Triggers>
        <!--
        <i:EventTrigger EventName="ProcessingEvent" SourceObject="{Binding}">
            <i:InvokeCommandAction Command="{x:Static view:ViewCommands.OpenProcessingDialog}" CommandParameter="{Binding}" />
        </i:EventTrigger>
        -->        
        <ei:DataTrigger Binding="{Binding IsProcessing}" Value="True">
            <i:InvokeCommandAction Command="{x:Static view:ViewCommands.OpenProcessingDialog}" CommandParameter="{Binding}" />
        </ei:DataTrigger>
        <i:EventTrigger EventName="EventFileTooLarge" SourceObject="{Binding}">
            <i:InvokeCommandAction Command="{x:Static view:ViewCommands.ShowMessageBox}" CommandParameter="150 Mb size limit exceed|File too large" />
        </i:EventTrigger>
        <i:EventTrigger EventName="EventDateFormatException" SourceObject="{Binding}">
            <i:InvokeCommandAction Command="{x:Static view:ViewCommands.ShowMessageBox}" CommandParameter="Error while formatting date|Parsing error" />
        </i:EventTrigger>
        <i:EventTrigger EventName="EventLevelParseException" SourceObject="{Binding}">
            <i:InvokeCommandAction Command="{x:Static view:ViewCommands.ShowMessageBox}" CommandParameter="Error while parsing log level|Parsing error" />
        </i:EventTrigger>
        <i:EventTrigger EventName="EventLinePatternException" SourceObject="{Binding}">
            <i:InvokeCommandAction Command="{x:Static view:ViewCommands.ShowMessageBox}" CommandParameter="Begin line pattern error|regex error" />
        </i:EventTrigger>
        <i:EventTrigger EventName="EventDatePatternException" SourceObject="{Binding}">
            <i:InvokeCommandAction Command="{x:Static view:ViewCommands.ShowMessageBox}" CommandParameter="Date pattern error|regex error" />
        </i:EventTrigger>
        <i:EventTrigger EventName="EventLevelPatternException" SourceObject="{Binding}">
            <i:InvokeCommandAction Command="{x:Static view:ViewCommands.ShowMessageBox}" CommandParameter="Log level pattern error|regex error" />
        </i:EventTrigger>
        <i:EventTrigger EventName="UnauthorizedException" SourceObject="{Binding}">
            <i:InvokeCommandAction Command="{x:Static view:ViewCommands.ShowMessageBox}" CommandParameter="Unauthorized access error|access error" />
        </i:EventTrigger>        
        <i:EventTrigger EventName="EventGenericException" SourceObject="{Binding}">
            <i:InvokeCommandAction Command="{x:Static view:ViewCommands.ShowMessageBox}" CommandParameter="An undefined error occurred|generic error" />
        </i:EventTrigger>        
    </i:Interaction.Triggers>        

</view:BaseView>
